# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=openwsman
pkgver=2.7.0
pkgrel=0
pkgdesc="Opensource Implementation of WS-Management"
url="https://openwsman.github.io"
arch="all"
license="custom BSD-3-Clause"
options="!check"  # No test suite
makedepends="cmake swig openssl-dev perl-dev curl-dev python3-dev sblim-sfcc-dev libxml2-dev"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs"
source="$pkgname-$pkgver.tar.gz::https://github.com/Openwsman/openwsman/archive/v$pkgver.tar.gz
	fix-musl-build.patch
	default-config.patch"

# secfixes:
#   2.6.10-r0:
#     - CVE-2019-3833
#   2.6.4-r0:
#     - CVE-2016-2183

prepare() {
	default_prepare
	mkdir -p build
}

build() {
	cd "$builddir"/build
	cmake \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" \
		-DCMAKE_CXX_FLAGS="$CFXXLAGS $CPPFLAGS" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DPACKAGE_ARCHITECTURE=$CARCH \
		-DLIB=lib \
		-DUSE_PAM=NO \
		-DBUILD_PYTHON=OFF \
		-DBUILD_PYTHON3=ON \
		-DBUILD_RUBY_GEM=OFF \
		-DBUILD_JAVA=OFF \
	..
	make
}

check() {
	cd "$builddir"/build
}

libs() {
	pkgdesc="$pkgname libs (aka libwsman)"

	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/* \
		"$subpkgdir"/usr/lib/
}

package() {
	cd "$builddir"/build
	make DESTDIR="$pkgdir/" install

	mv "$pkgdir/usr/sbin/"* "$pkgdir/usr/bin"
	rmdir "$pkgdir/usr/sbin/"
	rm "$pkgdir"/etc/pam.d/$pkgname
	rmdir "$pkgdir/etc/pam.d/"
	install -Dp -m644 ../COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
}

sha512sums="e61792eafd09e3608c736091d2742049086adaf5fffcda9391e4712ed1dedf3a533546a6af61ea6ce49d4cf4fb3649cb168f20260c4e975797395d6e565c6c37  openwsman-2.7.0.tar.gz
d031a3fd5f30b71ef87d7fd9c241baf55c20953c175ab0eb6192f9971b7b8a3a9c18693fa2cd468ed7f7ef94170281b7db5e987ba1b88c92d64231e560e91542  fix-musl-build.patch
3c10cb34a0bb0d70461225c0944c0fdaf9aadba2c78ee8122dcf8b493190bc86db0252cc74a7fdb178a2d0a0c26fb3323a1cd8dce320fe21eb0ad2860e42a0f1  default-config.patch"
